home *** CD-ROM | disk | FTP | other *** search
- Path: linux.nildram.co.uk!news
- From: colin@greench.co.uk (Colin Wray)
- Newsgroups: comp.lang.c
- Subject: Re: Why does my program do this?
- Date: Fri, 05 Apr 1996 18:36:15 GMT
- Organization: Greenchurch Software Ltd
- Message-ID: <4k3p49$c0t@linux.nildram.co.uk>
- References: <4jnln2$95j@dfw-ixnews3.ix.netcom.com> <4jpe4s$db2@penage.cs.laurentian.ca>
- NNTP-Posting-Host: pppj.nildram.co.uk
- X-Newsreader: Forte Free Agent 1.0.82
-
- echan@nickel.laurentian.ca (Edward C. Chan) wrote:
-
- >>char scores[STUDENT][5];
- >>
- >> for (i=0; i <= students-1; i=i+1)
- >> {
- >> for (j=0; j <= tests-1; j=j+1)
- >> {
- >> gets(&scores[i][j]);
- >> }
- >> }
- >>
-
- >user error.
-
- >replace
-
- > gets(&scores[i][j]);
-
- >with
-
- > gets(scores[i][j]);
-
- >andeverything shall work fine. Actually, you are lucky that the programme
- >doesn't crash on you.
-
- >Hope that helps.
-
- >Ed.
-
- What a load of rubbish ! scores[i][j] is a single char whose address
- is scores[i] + j;
- The problem is that no space has been allocated for the string from
- gets(); He needs 5 strings for each student, so the solution is to
- declare scores[STUDENTS][TESTS][16]; (say). Then gets(scores[i][j]) is
- ok. Of course, an array of structs would be better.
- colin@greench.co.uk
-
-